<template>
  <div class="hospital">
    <!--   左侧导航菜单 -->
    <div class="menu">
      <el-menu :default-active="defaultActive" class="el-menu-vertical-demo">
        <div class="top">
          <el-icon><House /></el-icon>
          <span> / 医院信息</span>
        </div>
        <el-menu-item
          index="/hospital/bookingRegister"
          @click="go('/hospital/bookingRegister')"
        >
          <el-icon><Calendar /></el-icon>
          <span>预约挂号</span>
        </el-menu-item>
        <el-menu-item index="/hospital/detail" @click="go('/hospital/detail')">
          <el-icon><Document /></el-icon>
          <span>医院详情</span>
        </el-menu-item>
        <el-menu-item
          index="/hospital/bookingInstructions"
          @click="go('/hospital/bookingInstructions')"
        >
          <el-icon><Bell /></el-icon>
          <span>预约须知</span>
        </el-menu-item>
        <el-menu-item
          index="/hospital/suspensionInfo"
          @click="go('/hospital/suspensionInfo')"
        >
          <el-icon><Warning /></el-icon>
          <span>停诊信息</span>
        </el-menu-item>
        <el-menu-item index="/hospital/search" @click="go('/hospital/search')">
          <el-icon><Search /></el-icon>
          <span>查询/取消</span>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 右侧详情信息   -->
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>
<script lang="ts" name="Hospital" setup>
import {
  Calendar,
  Document,
  Bell,
  Search,
  Warning,
  House,
} from "@element-plus/icons-vue";
import router from "@/router";
import { onMounted, ref } from "vue";
import useHospitalDetailStore from "@/store/modules/hospitalDetail.ts";

let defaultActive = ref("/hospital/bookingRegister");

let hospitalDetailStore = useHospitalDetailStore();

onMounted(() => {
  setDefaultActive();
  let query = router.currentRoute.value.query;
  // 获取医院详情信息
  hospitalDetailStore.getHospitalInfo(query.hoscode);
  // 获取医院科室信息
  hospitalDetailStore.getHospitalDepartments(query.hoscode);
});

// 设置默认激活的菜单
function setDefaultActive() {
  let path = router.currentRoute.value.path;
  if (path !== "/hospital") {
    defaultActive.value = path;
  }
}

// 跳转子路由
function go(path: string) {
  router.push({
    path,
    query: router.currentRoute.value.query,
  });
  defaultActive.value = path;
}
</script>

<style lang="scss" scoped>
.hospital {
  margin-top: 70px;
  width: 1200px;
  min-height: 700px;

  display: flex;
  justify-content: space-between;
  .menu {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    .top {
      color: #7f7f7f;
      margin-left: 25px;
    }
  }
  .content {
    flex: 8;
  }
}
</style>
